package com.yonyou.cyxdms.sysAuth.service.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.awt.*;

@Component
@Slf4j
public class SimsunFont {

    public static final String fontPath = "classpath:fonts/simsun.ttc";

    private static Font font = new Font("宋体", 1, 1);

    @Autowired
    private ResourceLoader resourceLoader;

    @PostConstruct
    public void init() throws Exception {
        Resource resource = resourceLoader.getResource(fontPath);
        font = Font.createFont(Font.PLAIN, resource.getInputStream());
    }

    public static Font createFont(int style, int size) {
        return font.deriveFont(style, size);
    }
}
